
<template>
  <views class="facilitator_enterprise_list">
    <!-- 审核企业状态 模态框 -->
    <modelBox :show="check_enterprise_show">
      <div class="check_enterprise_status">
        <viewTitle :title="'审核企业'" :border="false"></viewTitle>
        <div class="check_enterprise flex flexC flexJp">
          <div class="flex flexJ center">
            <div class="title">企业名称:</div>
            <div class="content">{{check_enterprise_name}}</div>
          </div>
          <div class="flex flexJ center">
            <div class="title">审核状态:</div>
            <div class="content">
              <el-select v-model="check_enterprise_status">
                <el-option
                  v-for="item in check_enterprise_status_list"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </div>
          </div>
        </div>
        <!-- 确认 取消 -->
        <div class="confirm_cancel flex center">
          <el-button @click="check_enterprise_show = !check_enterprise_show">取消</el-button>
          <el-button type="primary" @click="check">确定</el-button>
        </div>
      </div>
    </modelBox>

    <viewTitle :title="'企业列表'" :border="false"></viewTitle>
    <!-- 搜索栏 服务商端 -->
    <div class="search flex flexC">
      <!-- 企业编号-企业名称-企业状态-上级代理商编号-所属服务商-客户经理-提交时间 -->
      <el-form ref="form" label-width="auto" :inline="true">
        <div class="search_input flex flexR">
          <div class="customer_number flex flexR center">
            <el-form-item label="所属代理商编号:">
              <el-input v-model="form.belong_agent_sn" placeholder="请输入代理商编号" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <div class="bank_statement flex flexR center">
            <el-form-item label="所属代理商:">
              <el-input v-model="form.agent_name" placeholder="请输入代理商名称" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <div class="their_facilitator flex flexR center">
            <el-form-item label="企业编号:">
              <el-input v-model="form.enterprise_sn" placeholder="请输入企业编号" :clearable="true"></el-input>
            </el-form-item>
          </div>

        </div>
      </el-form>
      <!--  按钮 (查询、重置、新增)-->
      <el-form ref="form" label-width="auto" :inline="true">
        <div class="pay_btn flex">
          <div class="bank_statement flex flexR center">
            <el-form-item label="企业名称:">
              <el-input v-model="form.enterprise_name" placeholder="请输入企业名称" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <div class="bank_statement flex flexR center">
            <el-form-item label="所属客户经理:">
              <el-input
                v-model="form.belong_client_manager_sn"
                placeholder="请输入客户经理"
                :clearable="true"
              ></el-input>
            </el-form-item>
          </div>
          <div class="pay_state flex flexR center">
            <el-form-item label="企业状态:">
              <el-select v-model="form.enterprise_status">
                <el-option
                  v-for="item in form.enterprise_state_list"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
        </div>
      </el-form>
      
      <el-form ref="form" label-width="auto" :inline="true">
         <div class="pay_btn flex">
          <div class="pay_time flex flexR center">
            <el-form-item label="创建时间:">
              <el-date-picker
                v-model="form.submission_time"
                value-format="timestamp"
                type="datetimerange"
                align="right"
                :default-time="['0:00:00','23:59:59']"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="pickerOptions"
              ></el-date-picker>
            </el-form-item>
          </div>
          <!-- 按钮（查询、重置、新增） -->
          <el-form-item>
            <div class="flex flexR pay_btn_list">
              <el-button type="primary" @click="query">查询</el-button>
              <el-button @click="reset">重置</el-button>
              <el-button
                type="primary"
                :style="{width:140+'px'}"
                @click="exportExcel"
                size="medium"
                icon="el-icon-download"
              >导出列表</el-button>
              <el-button type="danger" @click="add">新增</el-button>
            </div>
          </el-form-item>
         </div>
      </el-form> 

    </div>
    <!-- 展示列表 -->
    <div class="table_list">
      <el-table
        border
        :data="tableData"
        style="width: 100%;max-width:none;"
        :header-cell-style="getRowClass"
        :select-on-indeterminate="true"
        :fit="true"
        :lazy="true"
        max-height="450"
      >
        <el-table-column fixed="left" type="index" label="序号"></el-table-column>
        <el-table-column prop="enterprise_sn" label="企业编号" ></el-table-column>
        <el-table-column prop="enterprise_name" label="企业名称"></el-table-column>
        <el-table-column prop="enterprise_user" label="初始管理员账号" ></el-table-column>
        <el-table-column prop="agent_sn" label="所属代理商编号" ></el-table-column>
        <el-table-column prop="agent_name" label="所属代理商"></el-table-column>
        <el-table-column prop="user_name" label="所属客户经理"></el-table-column>
        <el-table-column prop="contact_name" label="企业联系人"></el-table-column>
        <el-table-column prop="mobile" label="手机号码" ></el-table-column>
        <el-table-column prop="province" label="所属地区" ></el-table-column>
        <el-table-column prop="status_name" label="企业状态" ></el-table-column>
        <el-table-column prop="enterprise_created_time" label="创建时间" ></el-table-column>
        <el-table-column label="操作" fixed="right" width="280">
          <template slot-scope="scope" class="table_operation flex flexR">
            <el-button @click="look(scope.row.enterprise_id)">查看</el-button>
            <el-button type="primary" @click="edit(scope.row.enterprise_id)">编辑</el-button>
            <el-button
              type="success"
              v-if="parseInt(scope.row.status) === 0"
              @click="check_show(scope.row.enterprise_id, scope.row.enterprise_name)"
            >审核</el-button>
            <!-- 待审核中的状态，可以进行审核 -->
            <el-button
              type="danger"
              v-if="parseInt(scope.row.status) === 1"
              @click="freeze(scope.row.enterprise_id, scope.row.status)"
            >冻结</el-button>
            <el-button
              type="warning"
              v-if="parseInt(scope.row.status) === 2"
              @click="freeze(scope.row.enterprise_id, scope.row.status)"
            >解冻</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="flex flexR paging">
        <el-pagination
          style="background:#fff; padding:10px 0"
          background
          layout="total, sizes,prev, pager, next, jumper"
          @size-change="handleSizeChange($event)"
          @current-change="changePage($event)"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pagination.page_size"
          :total="pagination.total_count"
          :current-page="pagination.current_page"
          :page-count="pagination.page_count"
        ></el-pagination>
      </div>
    </div>
  </views>
</template>



<script>
export default {
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      //  三段综合  企业端  代理商端  服务商端
      check_enterprise_id: 0, //审核对应的企业ID
      check_enterprise_show: false, //审核企业模态框
      check_enterprise_status: 1, //提交的审核企业状态值
      check_enterprise_status_list: [
        { value: 1, label: "审核通过" },
        { value: 2, label: "审核不通过" }
      ], //可选审核状态值列表
      check_enterprise_name: "", //审核的企业名称
      form: {
        enterprise_sn: "", // 企业编号
        enterprise_name: "", // 企业名称
        enterprise_status: null, //企业状态（0：待审核、1：正常、2：已冻结、3：审核不通过）
        enterprise_state_list: [
          { value: null, label: "全部" },
          { value: 0, label: "待审核" },
          { value: 1, label: "正常" },
          { value: 2, label: "已冻结" },
          { value: 3, label: "审核不通过" }
        ],
        belong_agent_sn: "", // 所属代理商编号
        agent_name:"",//所属代理商名称
        belong_client_manager_sn: "", // 所属客户经理编号
        submission_time: [] // 提交时间
      },
      tableData: [],
      download_url: "",
      pagination: {
        //分页数据
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      }
    };
  },
  computed: {
    post_data() {
      let data = {};
      if (this.form.submission_time && this.form.submission_time.length > 0) {
        // data.enterprise_created_start_time = this.form.submission_time[0] / 1000; //去掉后面的毫秒级
        // data.enterprise_created_end_time = this.form.submission_time[1] / 1000; //去掉后面的毫秒级
        data.enterprise_created_start_time =  this.form.submission_time[0]/1000
        data.enterprise_created_end_time = this.form.submission_time[1]/1000
      }
      data.enterprise_sn = this.form.enterprise_sn;
      data.enterprise_name = this.form.enterprise_name;
      if (this.form.enterprise_status !== null)
        data.enterprise_status = this.form.enterprise_status;
      data.belong_agent_sn = this.form.belong_agent_sn;
      data.agent_name = this.form.agent_name;
      data.belong_client_manager_sn = this.form.belong_client_manager_sn;
      data.pagination = this.pagination;
      return data;
    }
  },

  mounted() {
    this.$setRouteTitle();
    //进来就调首页列表接口
    this.query();
  },
  methods: {
    //    修改第一行样式
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background: #FAFAFA ";
      } else {
        return "";
      }
    },
    handleSizeChange(page_size) {
      //变动每页数量时
      this.pagination.page_size = page_size;
      this.query();
    },
    changePage(current_page) {
      //切换页码时
      this.pagination.page_start = current_page;
      this.query();
    },
    async query() {
      console.log("点击");
      //企业列表
      let { code, msg, data } = await this.$api.sendSync(
        this.$mapapi.f_enterpriseList,
        this.post_data
      );
      if (code != 200 && code != 501) {
        this.$message.error(msg);
        this.tableData = [];
        return;
      }
      this.tableData = data.list;
      this.pagination = data.pagination;
      this.download_url = data.download_url || "";
    },
    look(enterprise_id) {
      //查看企业详情
      this.$toRoutePath({
        path: "/facilitator_enterprise_list/facilitator_enterprise_list_look",
        edit: true,
        query: { enterprise_id }
      });
    },
    edit(enterprise_id) {
      //编辑企业
      this.$toRoutePath({
        path: "/facilitator_enterprise_list/facilitator_enterprise_list_amend",
        edit: true,
        query: { enterprise_id }
      });
    },
    freeze(enterprise_id, status) {
      //冻结/解冻企业
      let content_title = "";
      if (parseInt(status) === 1) {
        content_title = "冻结";
        status = 2;
      } else {
        content_title = "解冻";
        status = 1;
      }

      this.$confirm("确认" + content_title + "该企业?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let { code, msg } = this.$api.sendSync(
            this.$mapapi.f_updateEnterpriseStatus,
            { enterprise_id, status }
          );
          if (code != 200 && code != 501) {
            this.$message.error(msg);
            return;
          }
          this.$message.success(msg);
          this.query();
        })
        .catch(() => {
          this.$message.error("取消" + content_title);
        });
    },
    check_show(enterprise_id, enterprise_name) {
      this.check_enterprise_show = true; //审核企业模态框显示
      this.check_enterprise_id = enterprise_id; //对应的审核企业ID
      this.check_enterprise_name = enterprise_name; //对应的审核企业名称
    },
    check() {
      let { code, msg } = this.$api.sendSync(
        this.$mapapi.f_updateEnterpriseStatus,
        {
          enterprise_id: this.check_enterprise_id,
          status: this.check_enterprise_status
        }
      );
      if (code != 200) this.$message.error(msg);
      this.$message.success(msg);
      this.check_enterprise_show = false;
      this.query();
    },
    reset() {
      //重置
      this.form = {
        enterprise_sn: "",
        enterprise_name: "",
        enterprise_status: null,
        belong_agent_sn: "",
        agent_name:"",
        belong_client_manager_sn: "",
        submission_time: [],
        enterprise_state_list:this.form.enterprise_state_list,
      };
      this.query();
    },
    //导出
    exportExcel() {
      this.$import_excal(this.download_url || "");
    },
    add() {
      //新增
      console.log("come add");
      this.$toRoutePath({
        path: "/facilitator_enterprise_list/facilitator_enterprise_list_add",
        edit: true
      });
    }
  }
};
</script>


<style lang="less" :scope="true"  src="@/style/businessManagement/facilitator_enterprise_list.less" >
</style>